<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------

namespace api\shop\controller;

use think\Db;
//商城
class TimeController
{
    //创建任务
    public function index(){
        //nohup php think queue:work --daemon --queue 任务名称 &//常驻进程
        //队列文档：https://github.com/coolseven/notes/tree/master/thinkphp-queue
        //配置守护进程：https://www.kancloud.cn/dargon/supervisor/1134310
        $data = [
            'order_no' =>rand(100000,999999),
        ];
        $this->add($data['order_no']);
        $data = json_encode($data);
        $res = \think\Queue::later(30,'api\shop\controller\TaskController', $data, $queue = 'group1');
        var_dump($res);exit;
    }

    public function add($order_no){
        $data = [
            'name' => $order_no,
            'thumbnail' => 'thumbnail',
            'introduction' => 'jianjie',
            'detail' => '',
            'create_time' => time(),
            'update_time' => time(),
        ];
        Db::name('test')->insert($data);
    }
}
